<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .bxx {
            width: 400px;
            height: 200px;
            text-align: center;
            border: 1px solid #00c77a;
        }

        .bxx p {
            color: #00c77a;
            margin-top: 40px;
            font-size: 30px;
        }

        .bxx button {
            width: 80px;
            height: 40px;
            border: none;
            color: white;
            font-size: 20px;
            margin-top: 20px;
            background-color: #2b88fe;
        }
    </style>
</head>

<body>
    <div id="box">
        <parent></parent>
    </div>
    <template id="parentT">
        <div>
            <child :num="msg"></child>
        </div>
    </template>
    <template id="chiidT">
        <div class="bxx">
            <p>{{num}}</p>
            <button @click="minus()">减小1</button>
            <button @click="plus()">增加1</button>
        </div>
    </template>
    <script src="./js/vue.js"></script>
    <script>
        // vue实例 父组件
        let vm = new Vue({
            el: "#box",
            data: {

            },
            components: {
                parent: {
                    template: "#parentT",
                    data() {
                        return {
                            msg: 0
                        }
                    },
                    components: {
                        child: {
                            props: ["num"],
                            template: "#chiidT",
                            methods: {
                                plus() {
                                    this.num++
                                },
                                minus() {
                                    this.num--
                                    if (this.num <= 0) {
                                        this.num = 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        })
    </script>
</body>

</html>